package com.njpi.stu.attendance.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.njpi.stu.attendance.entity.CheckWork;
import com.njpi.stu.attendance.entity.LeaveNote;
import com.njpi.stu.attendance.mapper.CheckWorkMapper;
import com.njpi.stu.attendance.mapper.LeaveNoteMapper;
import com.njpi.stu.attendance.service.ICheckWorkService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 考勤表 服务实现类
 * </p>
 *
 * @author pxl
 * @since 2019-11-07
 */
@Service
public class CheckWorkServiceImpl extends ServiceImpl<CheckWorkMapper, CheckWork> implements ICheckWorkService {

    @Autowired
    private LeaveNoteMapper leaveNoteMapper;

    /**
     * 根据考勤id和学生姓名判断有无假条
     * @param checkWork
     * @param realName
     * @return
     */
    @Override
    public boolean hasLeavNote(CheckWork checkWork, String realName) {
        QueryWrapper queryWrapper=new QueryWrapper();
        Map param=new HashMap();
        param.put("user_name",realName);
        param.put("state",1);
        queryWrapper.allEq(param);
        List<LeaveNote> leaveNotes = leaveNoteMapper.selectList(queryWrapper);
        for (LeaveNote leaveNote : leaveNotes) {
            //签到开始的时间大于等于假条开始时间
            //签到开始时间小于假条结束时间
            int start = checkWork.getTimeStart().compareTo(leaveNote.getTimeStart());
            int end = leaveNote.getTimeEnd().compareTo(checkWork.getTimeStart());
            if(start>=0 && end>=0){
                return true;
            }else {
                return false;
            }
        }
        return false;
    }
}
